package cn.bonoon.controllers.recycle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.bonoon.core.plugins.RecycleServcie;
import cn.bonoon.entities.RecycleEntity;
import cn.bonoon.kernel.support.services.GenericService;
import cn.bonoon.kernel.web.controllers.AbstractGridController;
import cn.bonoon.kernel.web.controllers.GridButtonResolver;
import cn.bonoon.kernel.web.handlers.DialogDetailHandler;
import cn.bonoon.kernel.web.handlers.OperateIdHandler;
import cn.bonoon.kernel.web.handlers.OperateIdsHandler;

@Controller
@RequestMapping("s/sys/recycle")
public class RecycleController extends AbstractGridController<RecycleEntity, RecycleItem> {

	private final RecycleServcie service;

	@Autowired
	protected RecycleController(RecycleServcie service) {
		super(service);
		this.service = service;
	}

	@Override
	protected Class<RecycleItem> itemClass() {
		return RecycleItem.class;
	}

	protected GenericService<RecycleEntity> initLayoutGrid(LayoutGridRegister register) throws Exception {
		// DialogInsertHandler.toolbar(register, service, MessageEditor.class);
		// OperateIdsHandler.delete(register, service);
		// OperateIdsHandler.resume(register, service);
		OperateIdsHandler ids_handler = new OperateIdsHandler(RecycleServcie.RESUME, "恢复", service, register.getManager());
		OperateIdsHandler.toolbar(register, ids_handler, "icon-accept").ordinal(0);
		
		ids_handler = new OperateIdsHandler(RecycleServcie.DELETE, "删除", service, register.getManager());
		OperateIdsHandler.toolbar(register, ids_handler, "icon-del").ordinal(1);
		
		ids_handler = new OperateIdsHandler(RecycleServcie.REMOVE, "彻底删除", service, register.getManager());
		OperateIdsHandler.toolbar(register, ids_handler, "icon-del").ordinal(2);
		
		ids_handler = new OperateIdsHandler(RecycleServcie.CLEARALL, "清空", service, register.getManager());
		OperateIdsHandler.toolbar_clear(register, ids_handler, "icon-del").ordinal(3);
		
		ids_handler = new OperateIdsHandler(RecycleServcie.REMOVEALL, "彻底清空", service, register.getManager());
		OperateIdsHandler.toolbar_clear(register, ids_handler, "icon-del").ordinal(4);

		
		DialogDetailHandler.button(register, service, RecycleDetail.class).ordinal(0);
		// DialogUpdateHandler.button(register, service, MessageEditor.class);
		// OperateIdHandler.delete(register, service);
		// OperateIdHandler.resume(register, service);
		OperateIdHandler id_handler = new OperateIdHandler(RecycleServcie.RESUME, "恢复", service, register.getManager());
		GridButtonResolver gbr = OperateIdHandler.button(register, id_handler);
		gbr.status(-1, 0);
		gbr.ordinal(2);

		id_handler = new OperateIdHandler(RecycleServcie.DELETE, "删除", service, register.getManager());
		gbr = OperateIdHandler.button(register, id_handler);
		gbr.ordinal(3);

		id_handler = new OperateIdHandler(RecycleServcie.REMOVE, "彻底删除", service, register.getManager());
		gbr = OperateIdHandler.button(register, id_handler);
		gbr.ordinal(4);
		return null;
	}

}
